package card

import (
	log2 "github.com/name5566/leaf/log"
	"server/cfg"
	"server/game/bag"
	db3 "server/game/bag/db"
	"server/msg/jsonData"
)

func CreateCard(userId string, ctid int64) ([]CardInfo, error) {
	logic := NewCardLogic()
	return logic.newCard(userId, ctid)
}

func GetCardListByUserId(userId string) ([]CardInfo, error) {
	logic := NewCardLogic()
	return logic.cardListByUserId(userId)
}
func UpdateLevel(userId string, cardId, step int64) (map[string]interface{}, error) {
	var ret = make(map[string]interface{}, 0)
	logic := NewCardLogic()
	cardInfo, err := logic.cardInfoByUserIdAndCtId(userId, cardId)
	if err != nil {
		return ret, err
	}
	config := cfg.ConfigData.TbCardLevel.Get(int32(cardInfo.Level + step))
	bagList, err := bag.EnUseItem(userId, db3.RencaiExp, int(config.Exp))
	if err != nil {
		return ret, err
	}
	cardInfo.Level = cardInfo.Level + step
	ret, err = logic.upCardLevel(userId, cardId, cardInfo.Level)
	cardDataList := ret["card_list"].([]CardInfo)
	cardList := make([]jsonData.CardInfo, 0)
	for _, cardInfoTmp := range cardDataList {
		cardJsonInfo := jsonData.CardInfo{
			UserId:     cardInfoTmp.UserId,
			CardId:     cardInfoTmp.CardId,
			Star:       cardInfoTmp.Star,
			Level:      cardInfoTmp.Level,
			SkillList:  cardInfoTmp.SkillList,
			WorkList:   cardInfoTmp.WorkList,
			FateList:   cardInfoTmp.FateList,
			SkinSkill:  cardInfoTmp.SkinSkill,
			HolaList:   cardInfoTmp.HolaList,
			UniqueList: cardInfoTmp.UniqueList,
		}
		cardList = append(cardList, cardJsonInfo)
	}
	ret["card_list"] = cardDataList
	ret["bag"] = bagList
	return ret, nil
}

func UpdateStar(userId string, cardId, step int64) (map[string]interface{}, error) {
	var ret = make(map[string]interface{}, 0)
	logic := NewCardLogic()
	ret, err := logic.updateCardStar(userId, cardId, step)
	if err != nil {
		log2.Error("err msg is %v", err)
		return ret, err
	}
	return ret, nil

}

func UpdateSkillLevel(userId string, cardId int64, skillType int, skillId int64, step int64) (CardInfo, error) {
	logic := NewCardLogic()
	ret, err := logic.updateSkillLevel(userId, cardId, skillType, skillId, step)
	if err != nil {
		log2.Error("err msg is %v", err)
		return ret, err
	}
	return ret, nil
}

func GetUserAllCardNengLi(userId string) float32 {
	//cardList := getCardListByUserId(userId)
	//for _, cardInfo := range cardList {
	//cfg.ConfigData.TbCardBase.Get(int32(cardInfo.CTId)).
	//}
	return 100
}
